package com.lambda.hybrid.handler;

import android.content.ClipData;
import android.content.ClipboardManager;

import com.lambda.hybrid.Callback;

import org.json.JSONObject;

public class SetClipboardHandler extends AbstractHandler {
    private final ClipboardManager mClipboardMng;

    public SetClipboardHandler(ClipboardManager clipboard) {
        mClipboardMng = clipboard;
    }

    @Override
    public void onHandle(String data, Callback callback) throws Exception {
        JSONObject table = new JSONObject(data);
        ClipData clipData = ClipData.newPlainText(null, table.getString("data"));
        mClipboardMng.setPrimaryClip(clipData);
    }
}
